package com.cqfae.deploycentral.app.utils;

import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.Map;

@Component
public class CheckFileTypeUtil {

    // 缓存文件头信息-文件头信息
    protected static final Map<String, String> mFileTypes = new HashMap<>();
    // 缓存文件头信息-脚本信息
    protected static final Map<String, String> mSqlTypes = new HashMap<>();
    static {
        mFileTypes.put("FFD8FF", "jpg");
        mFileTypes.put("89504E47", "png");

        mFileTypes.put("255044462D312E", "pdf");
        mFileTypes.put("D0CF11E0", "xls,doc,ppt");   //office2003版本文件
        mFileTypes.put("504B0304", "docx,xlsx,pptx");//office2007以上版本文件
        mFileTypes.put("52617221", "rar");

        mSqlTypes.put("63726561","sql");
    }

    public boolean jagementFileSuffix(String fileSuffix,String type){
        String appName = "doc、docx、xls、xlsx、ppt、pptx、pdf、jpg、png、rar、zip、properties、yaml、yml、xml、txt"+
                "DOC、DOCX、XLS、XLSX、PPT、PPTX、PDF、JPG、PNG、RAR、ZIP、PROPERTIES、YAML、YML、XML、TXT";
        if("file".equals(type) && appName.contains(fileSuffix)){
            return false;
        }
        String sqlName = "sql,SQL,zip,ZIP";
        if("sql".equals(type) && sqlName.contains(fileSuffix)){
            return false;
        }
        return true;
    }

}
